package com.feizhoutuobang.shapeline.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.feizhoutuobang.shapeline.bo.Subscription;
import com.feizhoutuobang.shapeline.bo.SubscriptionFeed;
import com.feizhoutuobang.shapeline.dao.SubscriptionDao;

public class SubscriptionDaoImpl extends HibernateDaoSupport implements SubscriptionDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Subscription> getAutoDeliverSubscription() {
		String hql = "from Subscription where autoDeliver=true";
		Query query = getSession().createQuery(hql);
		return query.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SubscriptionFeed> getFeedsOfSubscription(Subscription subscription) {
		String hql = "from SubscriptionFeed where subscriptionId=:subscriptionId";
		Query query = getSession().createQuery(hql).setString("subscriptionId", subscription.getId());
		return query.list();
	}

	@Override
	public void updateSubscription(Subscription subscription) {
		getHibernateTemplate().update("Subscription", subscription);
	}

	@Override
	public void updateLastPublishTime(SubscriptionFeed subscriptionFeed) {
		getHibernateTemplate().update("SubscriptionFeed", subscriptionFeed);
	}
}
